package com.cecsmsserve.util.config;

import com.cecsmsserve.util.JWTInterceptor;
import com.cecsmsserve.util.upload.FileUploadInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.*;

import javax.annotation.Resource;

@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private FileUploadInfo fileUploadInfo;

    @Resource
    private JWTInterceptor jwtInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
         *addResourceHandler:访问映射路径
         *addResourceLocations:资源绝对路径
         */
        //对哪个请求url路径进行处理 （/** 表示所有的请求处理）
        registry.addResourceHandler("/**")
                //资源的物理路径（请求的url与资源的物理路径进行映射）
                .addResourceLocations("classpath:/META-INF/resources/",
                        "classpath:/static/",
                        "classpath:/resources/",
                        "classpath:/public/",
                        //自定定义位置
                        "file:" + fileUploadInfo.getImageBasePath() + "/");

    }

//    @Override
//    public void configurePathMatch(PathMatchConfigurer configurer){
//        //指定controller统一的接口前缀，相当于在url上拼了一个 /api/xxx
//        configurer.addPathPrefix("/api",clazz->clazz.isAnnotationPresent(RestController.class));
//    }
}
